2020-2021 Sunseeker Telemetry and Lighting System
sd24_ex6_singleConversionSingleConversionTempSensor.c
Go to the documentation of this file.
1 /* --COPYRIGHT--,BSD
2  * Copyright (c) 2017, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  * --/COPYRIGHT--*/
32 //******************************************************************************
33 // MSP430i20xx SD24 Example 06 - SD24, Using the Integrated Temperature Sensor
34 //
35 // Description: This program uses the SD24 module to perform a single
36 // conversion on a single channel which is internally connected to the SD24's
37 // temperature sensor. Once the conversion is completed, the result is stored in
38 // a variable then converted into Celsius and Fahrenheit values.
39 //
40 // Test by setting a breakpoint at the indicated line. Upon reaching the breakpoint
41 // the conversion result will be stored in the results array. The result will
42 // then be taken and converted into degrees K, C, and F and be saved in the same
43 // array.
44 //
45 // ACLK = 32kHz, MCLK = SMCLK = Calibrated DCO = 16.384MHz, SD_CLK = 1.024MHz
46 // * Ensure low_level_init.c is included when building/running this example *
47 //
48 // Notes: For minimum Vcc required for SD24 module - see datasheet
49 // 100nF cap btw Vref and AVss is recommended when using 1.2V ref
50 //
51 // Sensor's temperature coefficient is 2.158mV/K (from datasheet)
52 // Sensor's offset voltage ranges from -100mv to 100mV (assume 0)
53 // Vsensor = 1.32mV * DegK + Vsensor_offset (assuming 0mv for offset)
54 // Vsensor = (SD24MEM0)/32767 * Vref(mV)
55 // DegK = (SD24MEM0 * 1200)/32767/2.158 = (SD24MEM0 * 1200)/70711
56 // DegC = DegK - 273
57 // DegF = (DegC * 9/5) + 32
58 //
59 //
60 // MSP430i20xx
61 // -----------------
62 // /|\| |
63 // | | |
64 // --|RST |
65 // | | (A0.6+/- connected internally)
66 // |A0.6+ VREF |---+ (to SD24's temperature sensor)
67 // |A0.6- | |
68 // | | -+- 100nF
69 // | | -+-
70 // | | |
71 // | AVss |---+
72 //
73 // T. Witt
74 // Yang Lu
75 // Texas Instruments, Inc
76 // June 2014
77 // Built with Code Composer Studio v5.5
78 //******************************************************************************
79 #include "driverlib.h"
80 
81 uint16_t results[4]; // SD24 Conversion and Temp Results
82  // results[0] = raw SD24 results
83  // results[1] = temp in K
84  // results[2] = temp in C
85  // results[3] = temp in F
86 
87 void main(void) {
88  // Stop WDT
89  WDT_hold(WDT_BASE);
90 
91  // Internal ref
92  SD24_init(SD24_BASE, SD24_REF_INTERNAL);
93 
94  //Ch0 single mode, internal temp sensor
95  SD24_initConverterAdvancedParam param = {0};
96  param.converter = SD24_CONVERTER_0;
97  param.conversionMode = SD24_SINGLE_MODE;
98  param.groupEnable = SD24_NOT_GROUPED;
99  param.inputChannel = SD24_INPUT_CH_TEMPERATURE;
100  param.dataFormat = SD24_DATA_FORMAT_2COMPLEMENT;
101  param.interruptDelay = SD24_FOURTH_SAMPLE_INTERRUPT;
102  param.oversampleRatio = SD24_OVERSAMPLE_256;
103  param.gain = SD24_GAIN_1;
104  SD24_initConverterAdvanced(SD24_BASE, &param);
105  SD24_enableInterrupt(SD24_BASE, SD24_CONVERTER_0, SD24_CONVERTER_INTERRUPT);
106 
107  // Delay ~200us for 1.2V ref to settle
108  __delay_cycles(3200);
109 
110  while(1) {
111  // Start conversion
112  SD24_startConverterConversion(SD24_BASE, SD24_CONVERTER_0);
113  // Enter LPM0 w/ interrupts
114  __bis_SR_register(LPM0_bits | GIE);
115  // For debugger
116  __no_operation();
117 
118  // Calculate Temperatures in different scales
119  results[1] = ((unsigned long)results[0] * 1200)/70711;
120  results[2] = results[1] - 273;
121  results[3] = (results[2] * 9/5) + 32;
122 
123  __no_operation(); // SET BREAKPOINT HERE
124  }
125 }
126 
127 #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
128 #pragma vector=SD24_VECTOR
129 __interrupt void SD24_ISR(void) {
130 #elif defined(__GNUC__)
131 void __attribute__ ((interrupt(SD24_VECTOR))) SD24_ISR (void) {
132 #else
133 #error Compiler not supported!
134 #endif
135  switch (__even_in_range(SD24IV,SD24IV_SD24MEM3)) {
136  case SD24IV_NONE: break;
137  case SD24IV_SD24OVIFG: break;
138  case SD24IV_SD24MEM0:
139  // Save CH0 results (clears IFG)
140  results[0] = SD24_getHighWordResults(SD24_BASE, SD24_CONVERTER_0);
141  break;
142  case SD24IV_SD24MEM1: break;
143  case SD24IV_SD24MEM2: break;
144  case SD24IV_SD24MEM3: break;
145  default: break;
146  }
147  __bic_SR_register_on_exit(LPM0_bits); // Wake up from LPM0
148 }
MPU_initThreeSegmentsParam param
__no_operation()
__delay_cycles(500000)
__bic_SR_register_on_exit(LPM0_bits)